package com.example.constraintlayoutstudy.check;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import com.example.constraintlayoutstudy.LoginActivity;

public class LoginStatusCheck extends StatusCheck {
  @Override boolean doCheck(Context context) {
    if (!StatusHolder.sHasLogin) {
      onCheckNotPassed(context);
    }
    return StatusHolder.sHasLogin;
  }

  private String getTitle() {
    return "登录检查";
  }

  private String getNotPassedMsg() {
    return "未登录，请先登录之后再继续后续操作";
  }

  private void onConfirm(Context context) {
    context.startActivity(new Intent(context, LoginActivity.class));
    //context.startActivity(new Intent(context, TestActivity.class));
  }

  private void onCheckNotPassed(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
        .setTitle(getTitle())
        .setMessage(getNotPassedMsg())
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            onConfirm(context);
            //Toast.makeText(context,"打印",Toast.LENGTH_LONG).show();
            //dialog.cancel();
          }
        }).setNegativeButton("取消", null);

    builder.show();
  }
}
